import type { TableProps } from "ant-design-vue";

export function useRowSelection(options?: TableProps['rowSelection']) {
  const rowSelection = ref<TableProps['rowSelection']>({
    fixed: true,
    onChange(selectedRowKeys) {
      if (rowSelection.value) {
        rowSelection.value.selectedRowKeys = selectedRowKeys;
      }
    },
    selectedRowKeys: [],
    type: 'checkbox',
    columnWidth: 60,
    preserveSelectedRowKeys: false,
    ...options,
  });
  function clearSelection() {
    if (rowSelection.value) {
      rowSelection.value.selectedRowKeys = []
    }
  }
  return {
    rowSelection,
    clearSelection
  };
}